#include "kernel/types.h"
#include "user/user.h"

void ReadFromPipes(int p) {
    char buf[6];
    read(p, buf, 6);
    printf("%d: received %s", getpid(), buf);
    close(p);
}

int main() {
    int p[2];
    pipe(p);

    int pid = fork();

    if (pid == 0) {
        ReadFromPipes(p[0]);
        write(p[1], "pong\n", 5);
        close(p[1]);

        exit(0);
    }
    else {
        write(p[1], "ping\n", 5);
        close(p[1]);
        wait(0);

        ReadFromPipes(p[0]);
    }

    exit(0);
}